package pers.jsan.litheopen.security.filter.authorize;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import pers.jsan.litheopen.security.exception.LitheAuthenticationException;
import pers.jsan.litheopen.security.filter.AuthenticationFilterChain;
import pers.jsan.litheopen.security.filter.LitheAuthenticationFilter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class AuthorizeParamsFilter implements LitheAuthenticationFilter {

    @Override
    public void doFilter(HttpServletRequest servletRequest, HttpServletResponse servletResponse, AuthenticationFilterChain filterChain) throws IOException, ServletException, LitheAuthenticationException {
        String response_type = servletRequest.getParameter("response_type");
        String client_id = servletRequest.getParameter("client_id");
        String redirect_uri = servletRequest.getParameter("redirect_uri");
        if(StringUtils.isEmpty(response_type) || StringUtils.isEmpty(client_id) || StringUtils.isEmpty(redirect_uri)) {
            throw new LitheAuthenticationException("请求的授权类型异常");
        }
        filterChain.doFilter(servletRequest, servletResponse);
    }
}
